package org.dbc;

import java.sql.*;;

public class DatabaseConnection {
    private Connection con=null;
	public DatabaseConnection(){
		try{     
			Class.forName("oracle.jdbc.OracleDriver");        //加载oracle驱动
			}
			catch(ClassNotFoundException e){
			System.out.println("加载驱动程序失败!");}    
			try{
				String url = "jdbc:oracle:thin:@"+System.getenv().get("COMPUTERNAME")+":1521:orcl"; 
			 String name="system";
		     String password1="xg123";
			 con=DriverManager.getConnection(url,name,password1);//连接数据库
			}catch(SQLException e){
		System.out.println("连接数据库失败!");
	}
	
	}
	public Connection getConnection(){
		return con;                     //返回连接对象
	}
	public boolean close() throws Exception{
		if(con!=null)
			{con.close();           //关闭连接
			return true;}
		  return false;
	}
}
